<?php namespace Admin\Controller; 

use Hdphp\Controller\Controller;

//后台首页控制器
class IndexController extends CommonController{
	
    //后台首页
    public function index(){
       View::make();
    }
	//后台欢迎界面
	public function welcome(){
	    View::make();
	}
	//修改密码
	public function updatePassword(){
		if(IS_POST){
			//1.判断原始密码
			$oldPassword = Q('post.oldPassword','','md5');
			//拿到已经登录的用户的auid
			$adminuserData = Db::table('adminuser')->where("auid={$_SESSION['auid']}")->get();
			if($oldPassword != $adminuserData[0]['password']){
				$this->error('原始密码不正确');
			}
			
			//2.判断新密码两次是否相同
			if(Q('post.newPassword') != Q('post.confirmPassword')){
				$this->error('新密码两次输入不相同');
			}
			
			//3.修改
			$newPassword = Q('post.newPassword','','md5');
			Db::table('adminuser')->where("auid={$_SESSION['auid']}")->update(array('password'=>$newPassword));
			
			//4.重新登录
			$url = U('login/index');
			$str = <<<str
<script>		
parent.location.href = '{$url}';
</script>
str;
			echo $str;exit;
		}
		View::make();
	}
}
